package com.mes.cloud.util;

import com.google.common.collect.Maps;

import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;

/**
 * @ProjectName: cloud
 * @Package: com.mes.cloud.util
 * @ClassName: ObjectToList
 * @Author: pactera
 * @Description: 将对象转化为Ojbject
 * @Date: 2019/4/26 13:53
 * @Version: 1.0
 */
public class ObjectToList {
/**
* 获取利用反射获取类里面的值和名称
*
* @param obj
* @return map
* @throws IllegalAccessException
*/
    public static Map<String, Object> objectToMap(Object obj) throws Exception {
                 Map<String, Object> map = Maps.newHashMap();
                 Class<?> clazz = obj.getClass();
                 for (Field field : clazz.getDeclaredFields()) {
                         field.setAccessible(true);
                         String fieldName = field.getName();
                         Object value = field.get(obj);
                         map.put(fieldName, value);
                     }
                 return map;
             }
}
